<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page isELIgnored="false"  %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath %>">
<!-- <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script> -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
	$(function (){
		/* $.getJSON("js/json/class_1.js",function(data){
			$(data).each(function(i,json){
				$("#attr_class_1_select").append("<option value="+json.id+">"+json.flmch1+"</option>");
			});
		}); */
		$('#attr_class_1_select').combobox({    
		    url:'js/json/class_1.js', 
		    method:'GET',
		    valueField:'id',    
		    textField:'flmch1',
		    width:'100',
		    onSelect:function get_attr_class_2(){
		    	var class_1_id = $(this).combobox('getValue');
		    	$('#attr_class_2_select').combobox({
	    		 	url:"js/json/class_2_"+class_1_id+".js", 
		 		    method:'GET',
		 		    valueField:'id',    
		 		    textField:'flmch2',
		 		    width:'100',
		 		    onSelect:function get_attr_list(flbh2){
		 				// 异步查询
		 				/* $.post("get_attr_list.do",{flbh2:flbh2},function(data){
		 					$("#attrListInner").html(data);
		 				}); */
		 				var flbh2 = $(this).combobox('getValue');
		 				$('#attrListInner').datagrid({    
		 				    url:'get_attr_list_json.do',
		 				    queryParams: {
		 				    	flbh2:flbh2
		 					},
		 				    columns:[[    
		 				        {field:'id',title:'id'},    
		 				        {field:'shxm_mch',title:'属性名'},    
		 				        {field:'list_value',title:'属性值',
		 				        	formatter:function(json,row,index){
		 				        		var result = ""
		 				        		$.each(json,function(i,item){
		 				        			result+=item.shxzh+item.shxzh_mch+";"
		 				        		});
		 				        		return result;
		 							}
		 						},    
		 				        {field:'chjshj',title:'创建时间',
		 								formatter:function(json,row,index){
		 				        		var date = new Date(json)
		 				        		return date.toLocaleString();
		 							}}    
		 				    ]]    
		 				}); 
		 				
		 			}
		    	});
		    	//combobox('reload', "js/json/class_2_"+class_1_id+".js");
			}
		});  
		
	});
	
	/* function get_attr_class_2(class_1_id){
		$.getJSON("js/json/class_2_"+class_1_id+".js",function(data){
			$("#attr_class_2_select").empty();
			$(data).each(function(i,json){
				$("#attr_class_2_select").append("<option value="+json.id+">"+json.flmch2+"</option>");
			});
		});
	} */
	
	function goto_attr_add(){
		var class_2_id = $("#attr_class_2_select").combobox('getValue');
		//var class_2_id = $("#attr_class_2_select").val();
		add_tab("goto_attr_add.do?flbh2="+class_2_id,'添加商品属性');
		//window.location.href="goto_attr_add.do?flbh2="+class_2_id;
	}
	
	function get_attr_list(flbh2){
		// 异步查询
		/* $.post("get_attr_list.do",{flbh2:flbh2},function(data){
			$("#attrListInner").html(data);
		}); */
		$('#attrListInner').datagrid({    
		    url:'get_attr_list_json.do',
		    queryParams: {
		    	flbh2:flbh2
			},
		    columns:[[    
		        {field:'id',title:'id'},    
		        {field:'shxm_mch',title:'属性名'},    
		        {field:'list_value',title:'属性值',
		        	formatter:function(json,row,index){
		        		var result = ""
		        		$.each(json,function(i,item){
		        			result+=item.shxzh+item.shxzh_mch+";"
		        		});
		        		return result;
					}
				},    
		        {field:'chjshj',title:'创建时间',
						formatter:function(json,row,index){
		        		var date = new Date(json)
		        		return date.toLocaleString();
					}}    
		    ]]    
		}); 
		
	}
</script>
<title>硅谷商城</title>
</head>
<body>
	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',split:true,border:false" style="height:100px">
			<div style="margin-left:30px;margin-top:30px">
			商品属性信息管理
			<hr>
			一级：<select id="attr_class_1_select" class="easyui-combobox"><option>请选择</option></select>
			二级：<select  id="attr_class_2_select" class="easyui-combobox"><option>请选择</option></select>
			</div>
		</div>
		<div data-options="region:'west',split:true,border:false" style="width:100px">
			查询<br>
			<a href="javascript:goto_attr_add()">添加</a><br>
			删除<br>
			编辑<br>
		
		</div>
		<div data-options="region:'center',border:false">
			<div id="attrListInner" class="easyui-datagrid">
				<!-- <table id="dg"></table>  -->
				
			
			</div>
		
		</div>
	</div>
	
	<br>
	
	<hr>
	
</body>
</html>